package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Curriculum;
import cn.wolfcode.crm.query.CurriculumQueryObject;
import cn.wolfcode.crm.service.ICurriculumService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("curriculum")
public class CurriculumController {

    @Autowired
    private ICurriculumService curriculumService;

    @RequestMapping("")
    @RequiresPermissions(value = {"课程表首页","Curriculum:index"} ,logical = Logical.OR)
    public String index(){

        return "curriculum/list";
    }

    @RequestMapping("list")
    @RequiresPermissions(value = {"课程表列表","Curriculum:list"} ,logical = Logical.OR)
    @ResponseBody
    public PageResult list(CurriculumQueryObject qo){
        PageResult result = curriculumService.query(qo);
        return result;
    }

    @RequestMapping("save")
    @RequiresPermissions(value = {"课程表保存","Curriculum:save"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult save(Curriculum entity){
        JSONResult result = new JSONResult();
        try{
            curriculumService.save(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @RequiresPermissions(value = {"课程表更新","Curriculum:update"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult update(Curriculum entity){
        JSONResult result = new JSONResult();
        try{
            curriculumService.update(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }


    @RequestMapping("delete")
    @RequiresPermissions(value = {"课程表删除","Curriculum:delete"} ,logical = Logical.OR)
    @ResponseBody
    public JSONResult delete(Long id){
        JSONResult result = new JSONResult();
        try{
            curriculumService.delete(id);
        }catch(Exception e){
            e.printStackTrace();
            result.remark("操作失败");
        }
        return result;
    }

  /*  @RequestMapping("query")
    @ResponseBody
    public PageResult query(CurriculumQueryObject qo) {

        PageResult result = curriculumService.query(qo);

        return result;
    }

*/

}
